<script setup lang="ts">
import { peymentGetListApi } from '@/apis/card'
import type { ListParams } from '@/types'
import type { PaymentI } from '@/types/card.d.ts'
import { formatTagType } from '@/utils/format'
import { ref } from 'vue'

const listParams = ref<ListParams>({
  page: 1,
  pageSize: 8,
  carNumber: '',
  paymentStatus: undefined,
})
const list = ref<PaymentI[]>([])
const total = ref(0)
const getList = async () => {
  const res = await peymentGetListApi(listParams.value)
  list.value = res.rows
  total.value = res.total
}
getList()
const onSearch = () => {
  listParams.value.page = 1
  listParams.value.pageSize = 8
  getList()
}
const changePage = (page: number) => {
  listParams.value.page = page
  getList()
}
const changePageSize = (pageSize: number) => {
  listParams.value.page = 1
  listParams.value.pageSize = pageSize
  getList()
}
</script>

<template>
  <div class="page-container">
    <div class="header-container">
      <el-form
        :inline="true"
        label-width="100px"
        style="width: 100%"
        :model="listParams"
      >
        <el-form-item label="车牌号码:">
          <el-input
            placeholder="请输入车牌号码"
            style="width: 220px"
            v-model="listParams.carNumber"
          />
        </el-form-item>
        <el-form-item label="缴纳状态:">
          <el-select
            placeholder="请选择缴纳状态"
            style="width: 220px"
            v-model="listParams.paymentStatus"
          >
            <el-option label="全部" :value="undefined"></el-option>
            <el-option label="未缴纳" :value="0"></el-option>
            <el-option label="已缴纳" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="list">
      <el-table-column label="序号" type="index" width="80" align="center" />
      <el-table-column label="车牌号码" align="center" prop="carNumber" />
      <el-table-column label="收费类型" align="center" prop="chargeType" />
      <el-table-column label="停车总时长" align="center" prop="parkingTime" />
      <el-table-column
        label="缴纳费用(元)"
        align="center"
        prop="actualCharge"
      />
      <el-table-column label="缴纳状态" align="center" prop="paymentStatus">
        <template #default="{ row }">
          <el-tag :type="formatTagType(row.paymentStatus)">{{
            row.paymentStatus === 1 ? '已缴纳' : '未缴纳'
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="缴纳方式" align="center" prop="paymentMethod">
        <template #default="{ row }">
          {{
            row.paymentMethod === 'Alipay'
              ? '支付宝'
              : row.paymentMethod === 'Wechat'
                ? '微信'
                : '现金'
          }}
        </template>
      </el-table-column>
      <el-table-column label="缴纳时间" align="center" prop="paymentTime" />
    </el-table>
    <!-- 分页区域 -->
    <el-pagination
      v-model:current-page="listParams.page"
      v-model:page-size="listParams.pageSize"
      layout="total, prev, pager, next, slot, jumper"
      :total="total"
      @current-change="changePage"
    >
      <el-select
        v-model="listParams.pageSize"
        style="width: 95px"
        @change="changePageSize"
      >
        <el-option label="8条/页" :value="8" />
        <el-option label="10条/页" :value="10" />
        <el-option label="15条/页" :value="15" />
      </el-select>
    </el-pagination>
  </div>
</template>

<style lang="scss" scoped>
.page-container {
  padding: 20px;

  .el-form {
    width: 80%;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);

    ::v-deep(.el-form-item__label) {
      color: rgb(39, 39, 39);
      font-weight: 500;
    }
  }

  .el-table {
    height: 450px;

    ::v-deep(.el-table__header th) {
      background-color: rgb(237, 237, 237, 0.9);
      color: rgb(43, 37, 37);
      padding: 10px 0;
    }

    ::v-deep(.el-table__body tr) {
      height: 50px;
    }
  }

  .el-pagination {
    display: flex;
    justify-content: flex-end;
    padding: 15px 0;
  }
}
</style>
